package mylib.archive.y2012.m08.SNSS_R3;

import mylib.dir.FastInputReader;
import mylib.dir.MatrixUtils;
import mylib.dir.PointF;

import java.io.PrintWriter;
import java.util.Locale;

public class TaskD {
    public void solve(int testNumber, FastInputReader in, PrintWriter out) {
        int n = in.nextInt();
        PointF[] p = new PointF[n];
        for (int i = 0; i < n; ++i) {
            double x = in.nextDouble();
            double y = in.nextDouble();
            p[i] = new PointF(x, y);
        }
        double[][] d = new double[n][n];
        MatrixUtils.fill(d, 1e200);
        for (int len = 1; len <= n; ++len)
            for (int l = 0; l + len - 1 < n; ++l) {
                int r = l + len - 1;
                if (Math.abs(l - r) <= 2) {
                    d[l][r] = 0;
                } else {
                    for (int mid = l + 1; mid < r; ++mid) {
                        double dd = (mid == l + 1 ? 0 : p[l].distance(p[mid])) + (mid + 1 == r ? 0 : p[mid].distance(p[r]));
                        d[l][r] = Math.min(d[l][r], dd + d[l][mid] + d[mid][r]);
                    }
                }
            }
        out.printf(Locale.US, "%.10f\n", d[0][n - 1]);
    }
}
